package com.example.a15954.myapplication.Activity;

import android.content.Intent;
import android.graphics.Point;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;

import com.example.a15954.myapplication.R;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();


       // getDisplayInfomation();
        //获取数字
        int abs = (int) Math.abs(2.5);
        int abs1 = (int) Math.abs(1);
        int abs2 = (int) Math.abs(0.3);
        int abs3 = (int) Math.abs(0.6);

        //获取内容：
        DisplayMetrics metric = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metric);
        int width = metric.widthPixels;// 屏幕宽度（像素）
        int height = metric.heightPixels;// 屏幕高度（像素）
        float density= metric.density;// 屏幕密度（0.75 / 1.0 / 1.5）
        int densityDpi = metric.densityDpi;// 屏幕密度DPI（120 / 160 / 240）
        System.out.println("宽度："+width+"   " + "高度："+"   "+height+"密度："+density+"密度DPI："+densityDpi);
    }

    private void initView() {
        Button xuni = (Button) findViewById(R.id.xuni);
        xuni.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //隐藏虚拟按键：
                hideBottomUIMenu();
            }
        });
        Button bt_click = (Button) findViewById(R.id.bt_click);
        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this,PxActivity.class));
            }
        });
        bt_click.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getDisplayInfomation();
            }
        });
    }

    private void getDisplayInfomation() {
        Point point = new Point();
        getWindowManager().getDefaultDisplay().getSize(point);
        Log.e("the screen size is ","the screen size is "+point.toString());
        Toast.makeText(MainActivity.this,"the screen size is "+point.toString(),Toast.LENGTH_LONG).show();
    }
    private void hideBottomUIMenu() {
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) {// lower api  
            View v = this.getWindow().getDecorView();
            v.setSystemUiVisibility(View.GONE);
        }else if (Build.VERSION.SDK_INT >= 19){
            View decorView = getWindow().getDecorView();
            int uiOptions =  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    |View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    |View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    |View.SYSTEM_UI_FLAG_FULLSCREEN
                    |View.SYSTEM_UI_FLAG_IMMERSIVE;
            decorView.setSystemUiVisibility(uiOptions);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
    }
}
